<layout name ="common" />
<div class="templatemo-content-widget no-padding">
	<div class="panel panel-default table-responsive">
		<table class="table table-striped table-bordered templatemo-user-table">
			<thead>
				<tr>
					<th colspan="7" style="font-size: 20px;">用户列表</th>
				</tr>
				<tr>
					<th style="text-align: center;"><a href="__ROOT__/user/userManage/order/id" class="white-text templatemo-sort-by">ID <span class="caret"></span></a></th>
					<th style="text-align: center;"><a href="__ROOT__/user/userManage/order/username" class="white-text templatemo-sort-by">Name <span class="caret"></span></a></th>
					<th style="text-align: center;"><a href="__ROOT__/user/userManage/order/email" class="white-text templatemo-sort-by">EMAIL <span class="caret"></span></a></th>
					<th style="text-align: center;"><a href="__ROOT__/user/userManage/order/count(*) desc" class="white-text templatemo-sort-by">文章数量 <span class="caret"></span></a></th>
					<th style="text-align: center;"><a href="__ROOT__/user/userManage/order/loginnum desc" class="white-text templatemo-sort-by">登录次数 <span class="caret"></span></a></th>
					<th style="text-align: center;"><a href="__ROOT__/user/userManage/order/lastdate desc" class="white-text templatemo-sort-by">最后登录时间 <span class="caret"></span></a></th>
					<th style="text-align: center;">操作</th>
				</tr>
			</thead>
			<tbody style="text-align: center;">
			<foreach name='userinfo' item='k'>
				<tr>
					<td>{$k.id}</td>
					<td>{$k.username}</td>
					<td>{$k.email}</td>
					<td>{$k.loginnum}</td>
					<td>
						<if condition='$k.artid eq null'>
						还未发布文章
						<else />
						{$k.count(*)}
						</if>
					</td>
					<td>
						<if condition='$k.lastdate eq null'>
						新用户未登录
						<else />
						{$k.lastdate|date='Y-m-d H:i:s',###}
						</if>
					</td>
					<td>
						<if condition='$admininfo.is_admin eq 1'>
						<a href="__ROOT__/user/editUser/id/{$k.id}" class="templatemo-is-btn">编辑</a>
						<a href="javascript:void(0)" onclick="delAdmin({$k.id})" class="templatemo-is-btn">删除</a>
						<else />
						<td>当前用户无法操作</td>
						</if>
					</td>
				</tr>
			</foreach>
			</tbody>
		</table>
		<div class="pagination-wrap">
			{$page}
		</div>
	</div>
</div>
<div class="templatemo-flex-row flex-content-row">
	<div class="col-1">
		<div class="panel panel-default margin-10">
			<div class="panel-heading"><h2 class="text-uppercase">添加用户</h2></div>
			<div class="panel-body">
				<form action="__ROOT__/user/addUser.html" class="templatemo-login-form" method="post">
					<div class="form-group">
						<label>用户名</label>
						<input type="text" class="form-control" id="inputEmail" placeholder="可以包含字母数字以及_,长度为6-20位" name="username">
					</div>
					<div class="form-group">
						<label>用户密码</label>
						<input type="password" class="form-control" placeholder="可以包含字母数字以及*_@#,长度为6-22位" name="password">
					</div>
					<div class="form-group">
						<label>确认密码</label>
						<input type="password" class="form-control" placeholder="确认密码" name="repassword">
					</div>
					<div class="form-group">
						<label>邮箱</label>
						<input type="email" class="form-control" placeholder="请输入正确格式邮箱" name="email">
					</div>
					<div class="form-group">
						<div class="checkbox squaredTwo">
							<i class="fa fa-arrow-circle-right fa-fw"></i><label>请遵守规则，发布积极向上的技术文章和心得</label><i class="fa fa-arrow-circle-left fa-fw"></i>
						</div>
					</div>
					<div class="form-group">
						<button type="submit" class="templatemo-blue-button">Submit</button>
					</div>
				</form>
			</div>
		</div>
	</div>
	<div class="templatemo-content-widget white-bg col-1">
		<i class="fa fa-times"></i>
		<div class="media margin-bottom-30">
			<div class="media-left padding-right-25">
				<a href="javascript:void(0)" onclick="change()">
				<if condition='$admininfo.headimg eq null'>
					<img class="media-object img-circle templatemo-img-bordered" src="__ADMIN__/images/person.jpg" alt="点击修改头像">
				<else />
					<img class="media-object img-circle templatemo-img-bordered" src="__ROOT__/{$admininfo.headimg}" alt="点击修改头像">
				</if>
				</a>
			</div>
			<div class="media-body">
				<h2 class="media-heading text-uppercase blue-text">{$admininfo.username}</h2>
			</div>
		</div>
		<div class="table-responsive">
			<div class="panel-heading"><h2 class="text-uppercase">我的发布<a class="media-heading text-uppercase blue-text" style="float: right;" href="__ROOT__/article/articleManage.html">查看更多</a></h2></div>
			<table class="table">
				<tbody>
					<foreach name='userArt' item='art'>
					<tr>
						<td><div class="circle green-bg"></div></td>
						<td width="40%"><a href="__ROOT__/article/showArt/id/{$art.id}">{$art.title}</a></td>
						<td>点击量：{$art.hits}</td>
					</tr>
					</foreach>
				</tbody>
			</table>
		</div>
	</div>
</div>
<div id="changeImg" style="display: none; text-align: center;">
	<div style="margin: 100px auto; width: 300px; height: 350px;background-color:#FFF;border: 2px solid #000;"  class="templatemo-content-widget white-bg col-1 text-center templatemo-position-relative">
		<a href="javascript:void(0)" id="hide"><i class="fa fa-times"></i></a>
		<img src="__ROOT__/{$admininfo.headimg}" alt="头像" class="img-circle img-thumbnail margin-bottom-30" style="width: 120px; height: 120px;">
		<h2 class="text-uppercase blue-text margin-bottom-5">更换头像</h2>
		<form id="imgForm" enctype="multipart/form-data">
			<a href="javascript:;" class="a-upload">
				<input type="file" id="file" name="file"><span class="showFileName">点击这里上传头像</span>
			</a>
			<br>
		</form>
		<button id="btn" class="templatemo-blue-button">提交</button>
	</div>
</div>
<script type="text/javascript">
	$(document).ready(function(){
		$("#leftMenu a[class='active']").removeClass("active");
		$('#leftMenu a:eq(3)').addClass("active");
	});
	function delAdmin(id){
		if(window.confirm("您确定要删除吗？")){
			window.location="__ROOT__/user/delUser/id/"+id;
		}
	}
	function change() {
		document.getElementById('changeImg').style.cssText='position: fixed; z-index:10; top:0px; left:0px; width: 100%; height: 100%; display: block; background-color: rgba(255,255,255,0.5);';
		$('#hide').show();
	}
	$("#file").change(function (){
		var file = this.files[0];
		var filePath=$(this).val();
		var arr=filePath.split('\\');
		var fileName=arr[arr.length-1];
		url = window.URL.createObjectURL(file);
		$(".showFileName").html(filePath);
		$("img[alt='头像']").attr('src',url);
	});
	$('#btn').click(function () {
		$.ajax({
			type: "POST",
			url: "__ROOT__/user/changeImg/id/{$admininfo.id}",
			cache: false,
			data: new FormData($("#imgForm")[0]),
			processData: false,
			contentType: false
		}).done(function(res) {
			$('#changeImg').hide();
			alert('修改成功');
			location.href="__ROOT__/user/userManage.html";
		}).fail(function(res) {
			alert(res);
		});
	});
	$('#hide').click(function () {
		$('#changeImg').hide();
	})
</script>